<?php
/*
 *	DreamArticle Version3.0
 *	Copyright 2007-2008, iDreamSoft
 *	http://www.idreamsoft.cn
 *	By:coolmoo<idreamsoft@qq.com>
*/
require_once("global.php");
$do=$_GET['do'];
$action=$_GET['action'];
$id=intval($_GET['id']);
switch ($do) {
case 'advertise':
	$ad=$DreamCMS->db->get_row("SELECT * FROM #DC@__advertise WHERE `id` ='$id' AND `status`='1' LIMIT 1");
	if(time() >= $ad->starttime && (time() <= $ad->endtime||empty($ad->endtime))){
		$ad->code=unserialize($ad->code);
		switch ($ad->style) {
		case "code":
			$html=stripslashes($ad->code["code"]['html']);
			break;
		case "image":
			$ad->code['image']['width'] && $width=" width=\"{$ad->code['image']['width']}\"";
			$ad->code['image']['height'] &&$height=" height=\"{$ad->code['image']['height']}\"";
			$html="<a href=\"{$ad->code['image']['link']}\" target=\"_blank\" title=\"{$ad->code['image']['alt']}\"><img src=\"{$ad->code['image']['url']}\" alt=\"{$ad->code['image']['alt']}\"{$width}{$height} alt=\"{$ad->code['image']['alt']}\" border=\"0\"></a>";
			break;
		case "flash":
			$ad->code['flash']['width'] && $width=" width=\"$ad->code['flash']['width']\"";
			$ad->code['flash']['height'] &&$height=" height=\"$ad->code['flash']['height']\"";
			$html="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" {$width}{$height}><param name=\"movie\" value=\"{$ad->code['flash']['url']}\" /><param name=\"quality\" value=\"high\" /><embed src=\"{$ad->code['flash']['url']}\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\"{$width}{$height}></embed></object>";
			break;
		case "text":
			$ad->code['text']['size'] &&$style=" style=\"font-size:{$ad->code['text']['size']};\"";
			$html="<a href=\"{$ad->code['text']['link']}\" target=\"_blank\" title=\"{$ad->code['text']['title']}\"{$style}>{$ad->code['text']['title']}</a>";
			break;
		}
		echo "document.write('".HTML2JS($html)."');\r\n";
	}
break;
case 'digg':
	if($action=='do'){
		$at=(time()-get_cookie('digg_'.$id)>$cookietime)?true:false;
		if($at){
			set_cookie('digg_'.$id,time(),$cookietime);
			if($id && $DreamCMS->db->query("UPDATE `#DC@__article` SET `digg` = digg+1  WHERE id='$id'")){
				echo "{state:'1'}";
			}
		}else{
			echo "{state:'0',text:'".jstr($DreamCMS->language('digged'))."' }";
		}
	}
	if($action=='show'){
		$digg=$DreamCMS->db->get_var("SELECT digg FROM `#DC@__article` WHERE id='$id' LIMIT 1");
		echo "document.write('{$digg}');\r\n";
	}
break;
case 'hits':
	$DreamCMS->db->query("UPDATE `#DC@__article` SET hits=hits+1 WHERE `id` ='$id' LIMIT 1");
	if($_GET['view']=='yes'){
		$hits=$DreamCMS->db->get_var("SELECT hits FROM `#DC@__article` WHERE id='$id'");
		echo "document.write('{$hits}');\r\n";
	}
break;
case 'comment':
	if(in_array($action,array('up','against'))){
		UA($action,(int)$_GET['cid']);
	}
	if($action=='show'){
		if($DreamCMS->config['iscomment']){
			$comments=$DreamCMS->db->get_var("SELECT comments FROM `#DC@__article` WHERE id='$id'  LIMIT 1");
			echo "document.write('{$comments}');\r\n";
		}
	}
break;
}
function UA($act,$cid){
	global $DreamCMS,$cookietime;
	$ajax=intval($_GET['ajax']);
	$ct=(time()-get_cookie($cid.'_up')>$cookietime && time()-get_cookie($cid.'_against')>$cookietime)?true:false;
	if($ct){
		set_cookie($cid.'_'.$act,time(),$cookietime);
		if($cid && $DreamCMS->db->query("UPDATE `#DC@__comment` SET `{$act}` = {$act}+1  WHERE `id` ='$cid'")){
			if($ajax){
				echo "{state:'1'}";
			}else{
				_Header($DreamCMS->dir."comment.php?aid=".$id);
			}
		}
	}else{
		if($ajax){
			echo "{state:'0',text:'".jstr($DreamCMS->language('digged'))."' }";
		}else{
			alert($DreamCMS->language('digged'));
		}
	}
}
?>